package cn.xm.basic.controller;

import cn.xm.basic.dto.BindUserDto;
import cn.xm.basic.dto.PhoneDto;
import cn.xm.basic.result.AjaxResult;
import cn.xm.basic.service.VerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@RequestMapping("/verify_code")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyService;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult getImage(@PathVariable("imageCodeKey") String imageCodeKey) {

        String imageEncode = verifyService.getImage(imageCodeKey);
        return AjaxResult.me().setResultObj(imageEncode);
    }

    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody PhoneDto phoneDto) {
        verifyService.sendSmscode(phoneDto);
        return AjaxResult.me();
    }

    /**
     * 绑定界面不需要图形验证码获取短信验证码
     * @param
     * @return
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody String phone) {
        verifyService.smsCode(phone);
        return AjaxResult.me();
    }

}
